<<<<<<< HEAD
package lesson7.pages;

import lesson5.ReportWriter;
import lesson7.WebDriverFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * User: alisa
 * Date: 29.03.14
 * Time: 22:07
 * To change this template use File | Settings | File Templates.
 */
public class AuthorizationPage extends BasePage {

    protected By loginPopup = By.name("signin");
    protected By fieldEmail = By.name("login");
    protected By fieldPassword = By.name("password");
    protected By submitButton = By.tagName("BUTTON");
    protected By authorizationEvidence = By.xpath("//*[@id=\"user_menu\"]/div[2]/a");
    protected By logoutButton = By.name("signout");

    public AuthorizationPage(WebDriver driver) {
        super(driver);
    }

    public void logIn(String testEmail, String testPassword) {

        driver.findElement(loginPopup).click();
        driver.findElement(fieldEmail);
        ReportWriter.logElementPresent("e-mail field");
        driver.findElement(fieldEmail).clear();
        driver.findElement(fieldEmail).sendKeys(testEmail);

        driver.findElement(fieldPassword);
        ReportWriter.logElementPresent("password field");
        driver.findElement(fieldPassword).sendKeys(testPassword);

        driver.findElement(submitButton).click();
        ReportWriter.logElementPresent("submit button");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    }

    public void logOut() {
        driver.findElement(logoutButton).click();
        ReportWriter.info("log out...");
        try {
            driver.findElement(authorizationEvidence).click();
            ReportWriter.info("something wrong, fix it");
        } catch (Exception e) {
            ReportWriter.info("logout SUCCESS");
        }
    }
}
=======
package lesson7.pages;

import lesson5.ReportWriter;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * User: alisa
 * Date: 29.03.14
 * Time: 22:07
 * To change this template use File | Settings | File Templates.
 */
public class AuthorizationPage extends BasePage {
    protected static String homeAddress = "http://rozetka.com.ua/";
    protected By loginPopup = By.name("signin");
    protected By fieldEmail = By.name("login");
    protected By fieldPassword = By.name("password");
    protected By submitButton = By.tagName("BUTTON");
    protected By authorizationEvidence = By.xpath("//*[@id=\"user_menu\"]/div[2]/a");
    protected By logoutButton = By.xpath("//*[@id=\"user_menu\"]/div[1]/a");
    protected By personalPage = By.xpath(".//span[contains(text(),'Личный кабинет')]");

    public AuthorizationPage() {
        super(driver);
    }

    @Override
    public void openPage() {
        driver.get(homeAddress);
        Assert.assertEquals(driver.getCurrentUrl(), homeAddress);
        driver.findElement(loginPopup).click();
    }


    public void logIn(String testemail, String testPassword) {
        WebElement emailField = driver.findElement(fieldEmail);
        ReportWriter.logElementPresent("e-mail field");
        emailField.clear();
        emailField.sendKeys(testemail);

        WebElement passwordField = driver.findElement(fieldPassword);
        ReportWriter.logElementPresent("password field");
        passwordField.sendKeys(testPassword);

        driver.findElement(submitButton).click();
        ReportWriter.logElementPresent("submit button");
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    }

    public void verifyLogin() {
        try {
            driver.findElement(authorizationEvidence).click();
            driver.findElements(personalPage);
            ReportWriter.info("authorization SUCCESS");
        } catch (Exception e) {
            ReportWriter.info("authorization FAILURE");
        }

    }

    public void verifyUnsuccessfulLogin() {
        try {
            String windowHandler = driver.getWindowHandle();
            driver.switchTo().window(windowHandler);
            ReportWriter.logElementPresent("Error popup");
        } catch (Exception e) {
            ReportWriter.logElementNotPresent("Error popup");
        }

    }

    public void logOut() {
        driver.findElement(logoutButton).click();
        ReportWriter.info("log out...");
        try {
            driver.findElement(authorizationEvidence).click();
            ReportWriter.info("something wrong, fix it");
        } catch (Exception e) {
            ReportWriter.info("logout SUCCESS");
        }
    }
}
>>>>>>> 08ceff2d8ef6c4ba599425ebdc1d58550dbc1fb6
